package com.ftg.learn.upload.controller;

import com.ftg.learn.common.result.Result;
import com.ftg.learn.upload.service.FileUploadService;
import com.ftg.learn.upload.vo.FileUploadVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/upload")
@Tag(name = "文件上传接口")
@Slf4j
public class UploadController {
    
    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("/single")
    @Operation(summary = "单文件上传", description = "支持图片和视频文件上传，最大文件大小10MB")
    public Result<FileUploadVO> uploadSingle(
            @Parameter(description = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        return fileUploadService.uploadFile(file);
    }
    
    @PostMapping("/batch")
    @Operation(summary = "批量文件上传", description = "支持多个图片和视频文件上传，每个文件最大10MB")
    public Result<List<FileUploadVO>> uploadBatch(
            @Parameter(description = "文件列表", required = true)
            @RequestParam("files") List<MultipartFile> files) {
        return fileUploadService.batchUploadFiles(files.toArray(new MultipartFile[0]));
    }
}
